// info.cpp
/*
用例来源：发布文档
编译方法：clang++ info.cpp -lOpenCL -o info && ./info
*/


#define CL_ENABLE_EXCEPTIONS
#define CL_USE_DEPRECATED_OPENCL_1_1_APIS
#define CL_USE_DEPRECATED_OPENCL_2_0_APIS
#include <iostream>
#include <CL/cl.hpp>
int main(int argc, char **argv) {
    cl_int err;
    std::vector<cl::Platform> platforms;
    try {
        err = cl::Platform::get(&platforms);
        std::cout << "Number of platforms:\t\t\t\t " << platforms.size() << std::endl;
        for (std::vector<cl::Platform>::iterator i = platforms.begin(); i != platforms.end(); ++i) {
            const cl::Platform &platform = *i;
            std::cout << " Platform Profile:\t\t\t\t " << platform.getInfo<CL_PLATFORM_PROFILE>().c_str() << std::endl;
            std::cout << " Platform Version:\t\t\t\t " << platform.getInfo<CL_PLATFORM_VERSION>().c_str() << std::endl;
            std::cout << " Platform Name:\t\t\t\t " << platform.getInfo<CL_PLATFORM_NAME>().c_str() << std::endl;
            std::cout << " Platform Vendor:\t\t\t\t " << platform.getInfo<CL_PLATFORM_VENDOR>().c_str() << std::endl;
        }
        std::cout << std::endl << std::endl;
        for (std::vector<cl::Platform>::iterator p = platforms.begin(); p != platforms.end(); ++p) {
            const cl::Platform &platform = *p;
            std::cout << " Platform Name:\t\t\t\t " << platform.getInfo<CL_PLATFORM_NAME>().c_str() << std::endl;
            std::vector<cl::Device> devices;
            platform.getDevices(CL_DEVICE_TYPE_ALL, &devices);
            std::cout << "Number of devices:\t\t\t\t " << devices.size() << std::endl;
            for (std::vector<cl::Device>::iterator i = devices.begin(); i != devices.end(); ++i) {
                const cl::Device &device = *i;
                std::string deviceName = device.getInfo<CL_DEVICE_NAME>();
                std::cout << " Device name:\t\t\t\t" << deviceName << std::endl;
            }
        }
    } catch (cl::Error err) {
        std::cerr << "ERROR: " << err.what() << "(" << err.err() << ")" << std::endl;
        return 1;
    }
    return 0;
}